// pages/test/test.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    height: 300,
    list: [],
    filePath: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.getImageInfo({
      src: 'https://bc.542124141.xyz/pam/images/canteen/dish/middle_3eb7d128f7404c1d9f5bda95d5178263.jpg',
      success (res) {
        wx.saveImageToPhotosAlbum({
          filePath: res.path,
          success(res){
            // console.log('save success!!!');
          }
        })
      },
      fail (err) {
        // console.log(err)
      }
    })
    setTimeout(() => {
      this.setData({
        list: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
      })
      wx.createSelectorQuery().select('#item0 .swiper-item').boundingClientRect((rect) => {
        this.setData( {
          height: rect.height + 150
        })
      }).exec()
    }, 10000)

    let _this = this
    const downloadTask = wx.downloadFile({
      url: 'https://sz.btfs.mail.ftn.qq.com/ftn_handler/eb9b9206a214d7c2f9500ebd59810dd23895dc01f31b091a39bb5e605cb0d4dde67a5a3440c955c8aadb5bcdc08c98a68542e58a2bbfb3a59421904aa501294e?compressed=0&dtype=1&fname=%E4%B8%A4%E6%96%B9%E5%8D%8F%E8%AE%AE.pdf', //仅为示例，并非真实的资源
      success (res) {
        if (res.statusCode === 200) {
          _this.setData({
            filePath: res.tempFilePath.slice(0, 20)
          })
          wx.openDocument({
            filePath: res.tempFilePath,
            showMenu: true,
            success: function (res) {
                // console.log('打开成功')
            }
          })
        }
      }
    })
    
    downloadTask.onProgressUpdate((res) => {
      // console.log('下载进度', res.progress)
      // console.log('已经下载的数据长度', res.totalBytesWritten)
      // console.log('预期需要下载的数据总长度', res.totalBytesExpectedToWrite)
    })
  },
  test: function () {
    wx.getImageInfo({
      src: 'https://bc.542124141.xyz/pam/images/canteen/dish/middle_3eb7d128f7404c1d9f5bda95d5178263.jpg',
      success (res) {
        // console.log(res)
      },
      fail (err) {
        // console.log(err)
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let list = this.data.list.concat([16, 17, 18, 19, 20])
      this.setData({
        list: list
      })
      wx.createSelectorQuery().select('#item0 .swiper-item').boundingClientRect((rect) => {
        this.setData( {
          height: rect.height + 150
        })
      }).exec()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})